package com.oig.sys.auth.dao;

import com.oig.sys.auth.entity.TbResourceQltmp;
import com.oig.sys.auth.vo.ResourceQltmpVo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
@author wuxl
*/
public interface ITbResourceQltmpDao extends JpaRepository<TbResourceQltmp, Integer> {

	TbResourceQltmp getTbResourceQltmpById(Integer id);


	@Query("select new com.oig.sys.auth.vo.ResourceQltmpVo(q.id,q.resourceId,q.queryName,q.userId,q.queryJson) from TbResourceQltmp q " +
			"where q.resourceId=:resourceId and (q.userId=:userId or q.userId=0)")
	List<ResourceQltmpVo> findByResourceIdAndUserId(@Param("resourceId") Integer resourceId, @Param("userId") Integer userId);

	@Query("select q.id from TbResourceQltmp q where q.userId=:userId ")
	List<Integer> findAllIdByUserId(@Param("userId") Integer userId);

	@Modifying
	@Query("delete from TbResourceQltmp q where q.id in(:idList)")
	void deleteByIdList(@Param("idList") List<Integer> idList);

}
